﻿#region LGPL
/************************************************************************************/
/* Fireball.Windows.Forms a controls library for windows forms
 * 
 * Copyright (C) 2009 Sebastian Faltoni
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the 
 * Free Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
 * for more details.
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, write to the Free Software Foundation, Inc., 59 
 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 * Signature of Sebastian Faltoni, 2 Febbraio 2009
 * Sebastian Faltoni, President of Orangebit
 * 
 ***********************************************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

namespace Orangebit.Windows.Forms
{
    /// <summary>
    /// Use the StackPanelItem as a Children for the StackPanel Control
    /// </summary>
    public class StackPanelItem : UserControl
    {
        /// <summary>
        /// The Children Control of this StackPanelItem
        /// </summary>
        public Control Child
        {
            get
            {
                if (base.Controls.Count == 0)
                    return null;
                return base.Controls[0];
            }
            set
            {
                base.Controls.Clear();
                base.Controls.Add(value);
            }
        }

        /// <summary>
        /// Don't use this property directly, use Child instead or you will get a bad behaviour
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new ControlCollection Controls
        {
            get
            {
                return base.Controls;
            }
        }

        /// <summary>
        /// The Container StackPanel
        /// </summary>
        public StackPanel StackPanel
        {
            get
            {
                return this.Parent as StackPanel;
            }
        }

        public StackPanelItem()
        {
            this.Fit = true;
        }

        /// <summary>
        /// The Docking Property canno't be used on this control
        /// </summary>
        public override System.Windows.Forms.DockStyle Dock
        {
            get
            {
                return DockStyle.None;
            }
            set
            {
                base.Dock = DockStyle.None;
            }
        }

        /// <summary>
        /// The anchor property canno't be used in this control
        /// </summary>
        public override AnchorStyles Anchor
        {
            get
            {
                return AnchorStyles.None;
            }
            set
            {
                base.Anchor = AnchorStyles.None;
            }
        }

        /// <summary>
        /// Is this is set to true the StackPanelItem it will be fitted on the opposite direction of the StackPanel 
        /// Orientation, es. if Orientation = Vertical this control it will be Fit Horizontally
        /// </summary>
        [DefaultValue(true)]
        public virtual bool Fit
        {
            get;
            set;
        }

        /// <summary>
        /// Set the width for this control
        /// </summary>
        /// <param name="w"></param>
        public virtual void SetWidth(int w)
        {
            this.Width = w;
            this.PerformLayout();
            this.Invalidate();
        }

        /// <summary>
        /// Set the height for this control
        /// </summary>
        /// <param name="h"></param>
        public virtual void SetHeight(int h)
        {
            this.Height = h;
            this.PerformLayout();
            this.Invalidate();
        }
    }
}
